class LED
{
private:
    int pin;
    bool active = false;

public:
    LED(const int led_pin = LED_BUILTIN, const boolean active_low = true)
    {
        this->pin = led_pin;
        this->active = active_low;
        pinMode(this->pin, OUTPUT);
    }

    bool state()
    {
        return (digitalRead(this->pin) == LOW) == this->active;
    }

    void set(bool state)
    {
        digitalWrite(this->pin, state == (this->active == LOW));
    }

    void toggle()
    {
        this->set(!this->state());
    }

    void on()
    {
        this->set(true);
    }

    void off()
    {
        this->set(false);
    }

    void blink(int t = 1, unsigned long ms = 100, bool toggle = true)
    {
        while (t > 0)
        {
            t--;
            delay(ms);
            toggle ? this->toggle() : this->on();
            delay(ms);
            toggle ? this->toggle() : this->off();
        }
    }
};